//
// Created by user on 2025/7/30.
//

#ifndef HELLOC_SENSITIVITY_H
#define HELLOC_SENSITIVITY_H
#include "systemc"
#include <iostream>
using namespace std;
using namespace sc_core;

class Sensitivity : public sc_module {
public:
    sc_event e1,e2;

    Sensitivity(sc_module_name name) : sc_module(name) {
        SC_THREAD(trigger_1);
        SC_THREAD(trigger_2);
        SC_THREAD(catch_static);
        SC_THREAD(catch_1or2_dyn);

        sensitive << e1 << e2;
    }

    void trigger_1() {
        wait(SC_ZERO_TIME); // delay trigger by a delta cycle, make sure catcher is ready
        while (true) {
            e1.notify(); // trigger e1
            wait(2, SC_SEC); // dynamic sensitivity, re-trigger after 2 s
        }
    }
    void trigger_2() { // delay trigger by a delta cycle
        wait(SC_ZERO_TIME);
        while (true) {
            e2.notify(); // trigger e2
            wait(3, SC_SEC); // dynamic sensitivity, re-trigger after 3 s
        }
    }

    void catch_1or2_dyn() {
        while (true) {
            wait(e1 | e2); // dynamic sensitivity
            std::cout << "Dynamic sensitivty: e1 or e2 @ " << sc_time_stamp() << std::endl;
        }
    }
    void catch_static(){
        while(true){
            wait();
            std::cout << "Static sensitivity: e1 or e2 @ " << sc_time_stamp() << std::endl;
        }
    }


};


#endif //HELLOC_SENSITIVITY_H
